package com.zhong.gang.pda.ui.action.receive;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.pda.R;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.pda.databinding.ActivityReceiveBinding;
import com.zhong.gang.pda.db.loction.LocationMessageUtils;
import com.zhong.gang.pda.ui.action.HuoBean;
import com.zhong.gang.pda.ui.action.HuoPersenter;
import com.zhong.gang.pda.ui.action.receive.controller.BaseReceiveController;
import com.zhong.gang.pda.ui.action.receive.controller.ReceiveActionController;

/**
 * 收货
 */
public class ReceiveAct extends ActBase<ActivityReceiveBinding> {
    private BaseReceiveController controller;
    private static final String ID = "ID";
    private static final String ISACTION = "ISACTION";
    private HuoPersenter persenter;
    public static final void openAct(Context context, int id, boolean isAction){
        Intent intent = new Intent(context, ReceiveAct.class);
        intent.putExtra(ID,id);
        intent.putExtra(ISACTION,isAction);
        context.startActivity(intent);
    }
    @Override
    public int LayoutRes() {
        return R.layout.activity_receive;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "订单详情";
    }

    @Override
    public void initView() {
        controller = new ReceiveActionController(ReceiveAct.this,getIntent().getIntExtra(ID,0),getIntent().getBooleanExtra(ISACTION,false));
        bind.setAct(this);
        persenter = new HuoPersenter();
        getData();
    }

    @Override
    public void getData() {
        super.getData();
        persenter.getDetailData(this,getIntent().getIntExtra(ID,0),this.new ActCallBack<BaseDataBean<HuoBean>>() {
            @Override
            public void onResponse(BaseDataBean<HuoBean> data) throws Exception {
                super.onResponse(data);
                HuoBean huoBean = LocationMessageUtils.getIntent(ReceiveAct.this).getData(data.getResult());
                if (data.getResult().getOrderReceive() == null && huoBean != null)
                    data.getResult().setOrderReceive(huoBean.getOrderReceive());
                controller.setScalesMsg(data.getResult());
            }
        });
    }

    public void onViewClicked(View view){
        controller.onViewClicked(view);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (controller instanceof ReceiveActionController){
            ((ReceiveActionController) controller).onActivityResult(requestCode,resultCode,data);
        }
    }
}
